package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.swgk.core.view.entity.TalentEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.view.ui.fragment.enterprise.PsTeamDetailTalentFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TalentFragModel extends BaseViewModel {
    private PsTeamDetailTalentFragment mFragment;

    public TalentFragModel(PsTeamDetailTalentFragment fragment) {
        this.mFragment = fragment;
    }

    public void getTalentQueryList(boolean isLodMore, String teamNo) {

        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTalentQueryThree(teamNo).enqueue(new Callback<BaseEntity<ListResponse<List<TalentEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<TalentEntity>>>> call, Response<BaseEntity<ListResponse<List<TalentEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mFragment.showList(response.body().getData().getList(), isLodMore);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<TalentEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
